-- magic_absorb
-- create by zhuangsl
-- 对单体造成伤害，并回复自身

return {
    apply = function(source, target, skillId, round, para, extra)
        -- 专属技能等级
        local level;
        local prop;
        extra = extra or {};
        if extra["level"] then
            level = tonumber(extra["level"]);
        else
            prop = PropM.combine(source, "gain_slime_skill", para[1]);
            level = PropM.apply(prop, 0);
        end

        -- 攻击方的魔力
        local magic = source:getMagic();

        -- 被对方百分比削弱
        prop = PropM.combine(target, "weak_enemy", "magic");
        magic = PropM.apply(prop, magic);

        -- 被对方绝对值削弱
        prop = PropM.combine(target, "weak_enemy2", "magic");
        magic = PropM.apply(prop, magic);

        -- 伤害
        local damage = math.modf(magic * para[2] * level / 1000);

        -- 斯巴达专属加成
        local prop = PropM.combine(source, "battle_cry", 1);
        if prop[3] > 0 then
            -- 触发特技发动事件
            EventMgr.fire(event.SPECIAL_SKILL_TRIGGER, { propId = prop[1] });
        end
        damage = PropM.apply(prop, damage);

        -- 增加命中动作
        SkillM.getSequence(target):hit(source, target, skillId);
        CombatM.receiveDamage(source, target, damage, skillId, extra);

        -- 恢复
        local count = math.modf(magic * para[4] * level / 1000);
        local bonus = { 2, para[3], count };
        BonusM.doBonus(bonus, "magic_absorb");

        -- 作用目标
        return { target, };
    end,

    parse = function(desc)
        local arr = string.explode(desc, ",");
        return { tonumber(arr[1]), tonumber(arr[2]), arr[3], tonumber(arr[4]) };
    end,

    -- 解析技能描述
    parseDesc = function(source, skillId, desc, para)
        -- 专属技能等级
        local prop = PropM.combine(source, "gain_slime_skill", para[1]);
        local level = PropM.apply(prop, 0);

        -- 攻击方的魔力
        local magic = source:getMagic();

        -- 伤害
        local damage = math.modf(magic * para[2] * level / 1000);

        -- 斯巴达专属加成
        prop = PropM.combine(source, "battle_cry", 1);
        damage = PropM.apply(prop, damage);

        desc = string.gsub(desc, "{damage}", damage);

        local absorb = math.modf(magic * para[4] * level / 1000);
        desc = string.gsub(desc, "{absorb}", absorb);

        -- 概率拘禁灵魂
        prop = PropM.combine(source, "skill_get_soul", skillId);
        if prop[3] > 0 then
            local rate = math.modf(prop[3] / 10);
            desc = string.gsub(desc, "{rate}", rate);
        end

        return desc;
    end,
};
